import datetime

from pydantic import BaseModel

from models.dbmodel import DbModel

# 状态0新任务1抓取中2停止3完成4异常终止

class TaskStatus:
    New = 0
    Running = 1
    Stop = 2
    Finish = 3
    Error = 4
    
class DbTask(DbModel):
    def __init__(self):
        self.id : str = 0
        self.user_id: int = 0
        self.name: str = ''
        self.proxy: str = ''
        self.platform_id: int = 0
        self.threads: int = 1
        self.car_numbers: str = ''
        self.status: TaskStatus = 0
        self.error: str = ''
        self.erased: int = 0
        self.gmt_create: datetime.datetime = None
        self.gmt_modified: datetime.datetime = None
        
class UiTask(DbTask):
    def __init__(self, dbtask: DbTask):
        for key in dbtask.__dict__.keys():
            setattr(self, key, getattr(dbtask, key))
        self.user_name: str = None
        self.create_time: str = None
        self.update_time: str = None

class NewTaskModel(BaseModel):
    name: str
    proxy: str
    platform_id: int
    threads: int
    car_numbers: str
    
class EditTaskModel(NewTaskModel):
    id: int
    
class OperationTaskModel(BaseModel):
    id: int
    name: str
